package org.millioncall.yueyoga.admin.service.stat;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象表格类
 * 
 * @author zangjinyu
 * @since 1.0.0
 * @version 1.0.0
 * 
 */
public class TableView extends HtmlTag {
	private String caption;// 标题
	private List<Tr> header;
	private List<Tr> body;
	private List<Tr> footer;

	public TableView() {
		super();
		this.header = new ArrayList<Tr>();
		this.body = new ArrayList<Tr>();
		this.footer = new ArrayList<Tr>();
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public List<Tr> getHeader() {
		return header;
	}

	public void setHeader(List<Tr> header) {
		this.header = header;
	}

	public List<Tr> getBody() {
		return body;
	}

	public void setBody(List<Tr> body) {
		this.body = body;
	}

	public List<Tr> getFooter() {
		return footer;
	}

	public void setFooter(List<Tr> footer) {
		this.footer = footer;
	}

	/**
	 * 取得总行数
	 * 
	 * @return
	 */
	public int getRows() {
		return this.header.size() + this.body.size() + this.footer.size();
	}

	/**
	 * 取得总列数
	 */
	public int getColumns() {
		if (this.header.size() > 0) {
			return countTds(this.header.get(0));
		} else if (this.body.size() > 0) {
			return countTds(this.body.get(0));
		} else if (this.footer.size() > 0) {
			return countTds(this.footer.get(0));
		} else {
			return 0;
		}
	}

	private int countTds(Tr tr) {
		int n = 0;
		for (Td td : tr.getTds()) {
			n += td.getColspan();
		}
		return n;
	}

}
